package com.jzo2o.foundations.controller.operation;


import com.jzo2o.common.model.PageResult;
import com.jzo2o.common.model.Result;
import com.jzo2o.foundations.model.dto.request.*;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 区域表 前端控制器
 * </p>
 *
 * @author itcast
 * @since 2023-07-03
 */
@Validated
@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 服务相关接口")
public class ServeController {

    @Autowired
    private IServeService serveService;

    /**
     * 服务分页查询
     *
     * @param servePageQueryReqDTO
     * @return ServeResDTO
     */
    
    @GetMapping("/page")
    @ApiOperation("服务分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO) {
        return serveService.findByPage(servePageQueryReqDTO);
    }

    /**
     * 批量保存服务
     *
     * @param serveUpsertReqDTOList
     * @return
     */
    @PostMapping("/batch")
    @ApiOperation("批量保存服务")
    public Result batchSave(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOList){
        serveService.batchSave(serveUpsertReqDTOList);
        return Result.ok();
    }

    /**
     * 服务价格修改
     *
     * @param id，price
     * @return
     */
    @PutMapping("/{id}")
    @ApiOperation("服务价格修改")
    private Result updatePrice(@PathVariable Long id, @RequestParam BigDecimal price) {

        serveService.updatePriceById(id,price);
        return Result.ok();
    }

    /**
     * 服务删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("服务删除")
    public Result delete(@PathVariable Long id) {
        return serveService.removeByIdAndStatus(id) ? Result.ok() : Result.error("删除失败");
    }

    /**
     * 服务上架
     *
     * @param id
     * @return
     */
    @PutMapping("/onSale/{id}")
    @ApiOperation("服务上架")
    public Result onSale(@PathVariable Long id) {
        serveService.onSale(id);
        return Result.ok();
    }

    /**
     * 服务下架
     *
     * @param id
     * @return
     */
    @PutMapping("/offSale/{id}")
    @ApiOperation("服务下架")
    public Result offSale(@PathVariable Long id) {
        serveService.offSale(id);
        return Result.ok();
    }

    /**
     * 服务设置热门
     *
     * @param id
     * @return
     */
    @PutMapping("/onHot/{id}")
    @ApiOperation("服务上架")
    public Result onHot(@PathVariable Long id) {
        serveService.onHot(id);
        return Result.ok();
    }

    /**
     * 服务取消热门
     *
     * @param id
     * @return
     */
    @PutMapping("/offHot/{id}")
    @ApiOperation("服务下架")
    public Result offHot(@PathVariable Long id) {
        serveService.offHot(id);
        return Result.ok();
    }
}
